/*
 * Copyright (C) 2022-2024, Xiaohua Semiconductor Co., Ltd.
 *
 * SPDX-License-Identifier: Apache-2.0
 *
 * Change Logs:
 * Date           Author       Notes
 * 2022-04-28     CDT          first version
 */

#ifndef _FAL_CFG_H_
#define _FAL_CFG_H_

#include <rtthread.h>
#include <board.h>
#include "drv_flash.h"
/* enable hc32f4 onchip flash driver sample */
#define FAL_FLASH_PORT_DRIVER_HC32F4
/* enable SFUD flash driver sample */
#define FAL_FLASH_PORT_DRIVER_SFUD

extern const struct fal_flash_dev hc32_onchip_flash;
extern struct fal_flash_dev ext_nor_flash0;



/* flash device table */
#define FAL_FLASH_DEV_TABLE                                          \
{                                                                    \
    &hc32_onchip_flash,                                              \
    &ext_nor_flash0,                                                 \
}

/* ====================== Partition Configuration ========================== */
#ifdef FAL_PART_HAS_TABLE_CFG
/* partition table */

#define FAL_PART_TABLE                                                                                                 \
{                                                                                                                      \
    /* 内部Flash分区 */                                                                                                \
    {FAL_PART_MAGIC_WORD,  "bootloader", "onchip_flash",         0,                        128*1024,        0},                \
    {FAL_PART_MAGIC_WORD,  "app",        "onchip_flash",         128*1024,                 368*1024,       0},                 \
    {FAL_PART_MAGIC_WORD,  "param",      "onchip_flash",         496*1024,                 8*1024,        0},                \
    {FAL_PART_MAGIC_WORD,  "otaparam",   "onchip_flash",         504*1024,                 8*1024,         0},                 \
                                                                                                                        \
    /* 外部SPI Flash分区 */                                                                                             \
    {FAL_PART_MAGIC_WORD,   "boot_backup",FAL_USING_NOR_FLASH_DEV_NAME,        0,                           128*1024,        0},    \
    {FAL_PART_MAGIC_WORD,   "app_backup", FAL_USING_NOR_FLASH_DEV_NAME,        128*1024,                    368*1024,       0},    \
    {FAL_PART_MAGIC_WORD,   "littlefs",   FAL_USING_NOR_FLASH_DEV_NAME,        496*1024,                    28.5*1024*1024, 0},    \
    {FAL_PART_MAGIC_WORD,   "log",        FAL_USING_NOR_FLASH_DEV_NAME,        496*1024+28.5*1024*1024,     2*1024*1024,    0},    \
    {FAL_PART_MAGIC_WORD,   "download",   FAL_USING_NOR_FLASH_DEV_NAME,        496*1024+30.5*1024*1024,     784*1024,       0},    \
    {FAL_PART_MAGIC_WORD,   "start",      FAL_USING_NOR_FLASH_DEV_NAME,        1280*1024+30.5*1024*1024,    128*1024,       0},    \
}
#endif /* FAL_PART_HAS_TABLE_CFG */

#endif /* _FAL_CFG_H_ */
